package com.algorithms.techniques;

import java.util.Map;

public  class Node<K,V> implements Map.Entry<K,V> 
{
	private K key;
	private V value;
	protected  Node<K,V> leftChild =null;
	protected Node<K,V> rightChild=null;
	protected Node<K,V> parent=null;
	
	public K getKey() 
	{
		return key;
	}
	
	public V getValue() 
	{
		return value;
	}
	
	public V setValue(V object) 
	{
		value=object;
		return value;
	}
	
	public void setKey(K key) {
		this.key = key;
	}

	public Node<K, V> getLeftChild() {
		return leftChild;
	}

	public void setLeftChild(Node<K, V> leftChild) {
		this.leftChild = leftChild;
	}

	public Node<K, V> getRightChild() {
		return rightChild;
	}

	public void setRightChild(Node<K, V> rightChild) {
		this.rightChild = rightChild;
	}

	public Node<K, V> getParent() {
		return parent;
	}

	public void setParent(Node<K, V> parent) {
		this.parent = parent;
	}
	
	@Override
	public String toString() {
		K rChild=null;
		K lChild=null;
		if(rightChild!=null)
			rChild=rightChild.getKey();
		if(leftChild!=null)
			lChild=leftChild.getKey();
		return "key="+key +",value="+ value + "\tLeftChild="+lChild+"\tRightChild="+rChild ;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Node other = (Node) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		
		return true;
	}
	
	
}